package org.rency.ues.engine.repository.impl;

import org.rency.ues.dal.dao.DataHashDao;
import org.rency.ues.dal.entity.DataHashDO;
import org.rency.ues.domain.model.DataHashDomain;
import org.rency.ues.engine.converter.DataHashConverter;
import org.rency.ues.engine.repository.DataHashRepository;

public class DataHashRepositoryImpl implements DataHashRepository {
	
	private DataHashDao dataHashDao;

	@Override
	public boolean save(DataHashDomain domain) {
		DataHashDO entity = DataHashConverter.convert(domain);
		boolean ret = dataHashDao.insert(entity) == 1;
		if(ret){
			domain.setId(entity.getId());
		}
		return ret;
	}

	@Override
	public boolean delete(int id) {
		return dataHashDao.delete(id) == 1;
	}

	@Override
	public boolean deleteByTicket(String ticket) {
		return dataHashDao.deleteByTicket(ticket) == 1;
	}

	@Override
	public boolean deleteByHash(String hash) {
		return dataHashDao.deleteByHash(hash) == 1;
	}

	@Override
	public DataHashDomain get(int id) {
		return DataHashConverter.convert(dataHashDao.get(id));
	}

	@Override
	public DataHashDomain getByTicket(String ticket) {
		return DataHashConverter.convert(dataHashDao.getByTicket(ticket));
	}

	@Override
	public DataHashDomain getByHash(String hash) {
		return DataHashConverter.convert(dataHashDao.getByHash(hash));
	}

	public void setDataHashDao(DataHashDao dataHashDao) {
		this.dataHashDao = dataHashDao;
	}

}
